<template>
    <div id='' class='tenantuser_content'>
        <i-table class="table_content" ref="myTable" :search="getSearch" :table="getTbale" :pageConfig="pageConfig" />
        <Modal v-model="modalShow" width="1200" :mask-closable="false" :title="modalTitle">
            <components v-if="modalShow" :is="comps" ref="coms" />
            <div slot="footer">
                <Button type="text" @click="cancel">取消</Button>
                <Button type="primary" @click="ok">确定</Button>
            </div>
        </Modal>

    </div>
</template>
<script>
import { config } from './user/table_config'
import addUpdata from "./user/add-updata.vue";
export default {
    name: '',
    props: [''],
    data() {
        return {
            search: {}, // 查询配置对象
            tableConfig: {}, // 表格配置对象
            pageConfig: config.page, // 翻页器配置
            comps: addUpdata,
            modalShow: false,
            modalTitle: '',
            removeContent: '',
            removeTitle: '',
            removeList: []
        };
    },
    components: {},
    computed: {
        getSearch() {
            this.search = icu.util.deepClone(config.search);// 为不改变原始配置数据，进行深度克隆。
            return this.search;
        },
        getTbale() {
            this.tableConfig = icu.util.deepClone(config.table); // 深度克隆表格配置。
            this.tableConfig.event = {
                edit: this.edit,
                add: this.add,
                remove: this.remove,
            }
            return this.tableConfig;
        }
    },
    beforeMount() { },
    mounted() { },
    methods: {
        add(row) {
            this.modalShow = true
            this.modalTitle = '新增'
            this.$nextTick(() => {
                this.$refs.coms.isAddOrEdit(true);
            })
        },
        edit(event, row) {
            this.modalShow = true
            this.modalTitle = '编辑'
            this.$http.$get('tenantUserRoleDetail', { params: { id: row.id } }).then(res => {
                if (res.code == 200) {
                    this.$nextTick(() => {
                        this.$refs.coms.isAddOrEdit(false);
                        this.$refs.coms.setData(res.data)
                    })
                    return
                }
                this.$Message.error(res.msg)
            })
        },
        getList() {
            this.$refs.myTable.seach();
        },
        ok() {
            this.$refs.coms.getForm((formRes) => {
                this.$http.$post('tenantUserRoleSave', { data: { ...formRes, ...{ tenantCode: formRes.tenantCode[formRes.tenantCode.length - 1] } } }).then(res => {
                    if (res.code == 200) {
                        this.$Message.success('保存成功');
                        this.cancel();
                        this.getList();
                        return
                    }
                    this.$Message.error(res.msg)
                })
            })
        },
        cancel() {
            this.modalShow = false
        },
        remove(item, row) {
            let _this = this;
            this.$Modal.confirm({
                title: '删除确认',
                content: '删除操作将删除该租户下所有相关数据，且不可恢复，请确定是否删除该租户？',
                onOk: () => {
                    _this.removeSure(item, row)
                },
            });
        },
        removeSure(item, row) {
            setTimeout(() => {
                this.$Modal.confirm({
                    title: '删除确认',
                    content: '请再次确认是否删除该租户？',
                    onOk: () => {
                        this.$http.$post('tenantUserRoleDelete', { data: [row.id] }).then(res => {
                            if (res.code == 200) {
                                this.$Message.success('删除成功');
                                this.getList()
                            } else {
                                this.$Message.error(res.msg);
                            }
                        })
                    },
                });
            }, 500)
        }
    },
    watch: {}
}
</script>
<style lang='less' scoped>
.tenantuser_content {
    background-color: #fff;
    padding: 0 20px;
    width: 100%;
    height: 800px;

    .table_content {
        height: 752px;
        overflow: auto;
    }
}
</style>